package com.etc.admin.controller;

import com.etc.entity.OneLevel;
import com.etc.entity.po.FlashOneLevelStatistics;
import com.etc.service.FlashOrderService;
import com.etc.utils.CommonMessage;
import com.etc.utils.PageData;
import com.etc.vo.OrderInfoMessage;
import com.etc.vo.UpdateFlashOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 文件名:com.etc.admin.controller.AdminFlashOrderController
 * 描述：后台秒杀订单控制器
 * 作者:吴仕泉
 * 时间:2019/5/29 4:32
 */
@Controller
@RequestMapping("adminflashorder.action")
public class AdminFlashOrderController {
    @Autowired
    FlashOrderService flashOrderService;

    //统计每周各大类的秒杀数据
    @RequestMapping("statisticsweekflashincome")
    @ResponseBody
    public List<FlashOneLevelStatistics> statisticsWeekFlashIncomeData(Integer page, Integer limit, String content){
        return flashOrderService.statisticsOneLevelData();
    }

    //以分页的形式展示订单的详细信息
    @RequestMapping("showflashordermessagebypage")
    @ResponseBody
    public PageData<OrderInfoMessage> showFlashOrderMessageByPage(Integer page, Integer limit){
        if(page<0||limit<0){
            return null;
        }
        if(page == 0){
            page = 1;
        }
        if(limit==0){
            limit = 10;
        }
        PageData<OrderInfoMessage> pd = flashOrderService.findAllFlashOrderByPage(page,limit);
        return pd;
    }

    //修改订单信息
    @RequestMapping(value = "updateflashordermessage" ,method = RequestMethod.POST)
    @ResponseBody
    public  CommonMessage updateFlashOrderMessage(@RequestBody UpdateFlashOrder ufo){
        CommonMessage commonMessage = new CommonMessage();
        System.out.println(ufo);
       boolean flag = flashOrderService.updateOrderMessage(ufo);
        if(!flag){
            commonMessage.setMsg("修改失败");

        }else{
            commonMessage.setMsg("修改成功");
        }
        return commonMessage;
    }

}
